package main;

import java.util.*;

public class Article {
    public String name;

    public int numberOfSynonyms;
    public List<String> synonyms;
    public int numberOfStrings;
    public List<String> stringsOfArticle;

    public Article(List<String> strings) {
        synonyms = new ArrayList<String>();
        stringsOfArticle = new ArrayList<String>();
        name = strings.get(0);
        numberOfSynonyms = Integer.parseInt(strings.get(1));
        for(int i = 2; i < numberOfSynonyms + 2; i++) {
            synonyms.add(strings.get(i));
        }
        numberOfStrings = Integer.parseInt(strings.get(numberOfSynonyms + 2));
        for(int i = numberOfSynonyms + 3; i < strings.size(); i++) {
            stringsOfArticle.add(strings.get(i));
        }
    }

    public List<List<String>> getWords() {
        List<List<String>> allWords = new ArrayList<List<String>>();
        List<String> n = new ArrayList<String>();// используется один раз для добавления имени
        n.add(name);
        allWords.add(n);
        List<String> textLine = new ArrayList<String>(stringsOfArticle);
        for(int i = 0; i < textLine.size(); i++) {
            String text = textLine.get(i);
            allWords.add(new ArrayList<String>(Arrays.asList(text.split("\\s+"))));
        }
        return allWords;
    }

    public void updateArticle(List<List<String>> allWords) {
        for(int i = 0; i < allWords.size(); i++) {
            String line = "";
            ArrayList<String> temp = new ArrayList<String>(allWords.get(i));
            if(i == 0) {
                name = temp.get(i);
                continue;
            }
            for(int j = 0; j < temp.size(); j++) {
                line += temp.get(j) + " ";
            }
            stringsOfArticle.set(i - 1, line);
        }
    }


    public boolean equals(Article article) {
        return this.name.equals(article.name) ? true : false;
    }

    @Override
    public String toString() {
        /*return "Article{" +
                "name='" + name + '\'' +
                ", numberOfSynonyms=" + numberOfSynonyms +
                ", synonyms=" + synonyms +
                ", numberOfStrings=" + numberOfStrings +
                ", stringsOfArticle=" + stringsOfArticle +
                '}';*/
        return "Article{" + name + "}";
    }
}
